<#include "./template/general_temp.ftl">

<#macro content>
<div class="row" xmlns:input="http://www.w3.org/1999/html" xmlns:input="http://www.w3.org/1999/html">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-edit"></i>编辑</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content">
				<#if !no_obj??>
					<@form.form modelAttribute="editPostsCommand" role="form" enctype="multipart/form-data">
						<@form.errors path='*' element="div" cssClass="alert alert-success" cssErrorClass="alert alert-danger"/>
						<#if no_error??>
                            <div class="alert alert-success">
                                <strong>Well done! </strong>文章保存成功。<a href="${base}/system/posts">点击这里</a>返回文章列表。
                            </div>
						</#if>
                        <#if type?? && type == 'moke'>
                        <#else>
                            <div class="form-group">
                                <label>文章分类</label>
                                <#list terms as t>
                                    <@form.radiobutton path="postTerm" value="${t.id}" label="${t.name}" />
                                </#list>
                            </div>
                        </#if>
                        <div class="form-group" id="imgBlock">
							<@form.hidden path="postImg" id="iconUrlImg"/>
							<#if editPostsCommand.postImg?? && editPostsCommand.postImg != "">
                                <img style='width:200px;' src='${base}/system/getImg?imgId=${editPostsCommand.postImg}'/>
							</#if>
                        </div>
                        <div class="form-group">
                            <label for="imgSel">选择文章主图</label>
                            <input data-no-uniform="true" type="file" id="imgSel" class="file_upload">
                        </div>
                        <div class="form-group">
                            <label for="postTitle">标题</label>
							<@form.input path="postTitle" cssClass="form-control" id="postTitle"/>
                        </div>
                        <div class="form-group">
                            <label for="postContent">内容(<span style="color:red;">图片说明不要在图片后面输入“回车键”，应直接在图片后面输入文字，并选择文字居中样式！</span>)</label>
							<@form.textarea path="postContent" id="postContent"></@form.textarea>
                        </div>
                        <#if type?? && type == 'moke'>
                        <#else>
                            <div class="form-group">
                                <label for="tags">相关产品关键词(<span style="color:red;">会根据该关键词搜索匹配相关产品标题</span>)</label>
                                <@form.input path="tags" cssClass="form-control" id="tags"/>
                            </div>
                        </#if>
                        <div class="form-group">
                            <label for="status">文章内容头部是否显示主图？</label>
                            <@form.radiobutton path="extra4" value="显示"/>显示
                            <@form.radiobutton path="extra4" value="不显示"/>不显示
                        </div>
                        <div class="form-group">
                            <label for="status">状态</label>
							<#if type??>
								<@form.radiobutton path="postStatus" value="待审核"/>待审核
								<@form.radiobutton path="postStatus" value="审核通过"/>审核通过
								<@form.radiobutton path="postStatus" value="审核不通过"/>审核不通过
							<#else>
								<@form.radiobutton path="postStatus" value="显示"/>显示
								<@form.radiobutton path="postStatus" value="隐藏"/>隐藏
							</#if>
                        </div>
                        <@form.hidden path="postType"/>
                        <button type="submit" class="btn btn-default">提交</button>
					</@form.form>
				<#else>
                    <div class="alert alert-danger">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>Oh snap!</strong>没有找到数据！
                    </div>
				</#if>
            </div>
        </div>
    </div>
    <!--/span-->
</div>
<!--/row-->
</#macro>

<#macro script>
<script type="text/javascript">
    UE.getEditor('postContent');

    //uploadify - multiple uploads
    $('#imgSel').uploadify({
        'swf': '${base}/system/charisma-static/misc/uploadify.swf',
        'uploader': '${base}/system/uploadImg',
        'fileTypeExts': '*.jpg;*.gif;*.jpeg;*.png;',
        'buttonText' : '请选择图片',
        'fileObjName':'file',
        'multi': false,
        onSelect : function(file) {//当每个文件添加至队列后触发
            if(file.size >= 2 * 1024 * 1024){
                alert("选择文件不能超过2MB");
                return false;
            }
        },
        onError: function(event, queueID, fileObj) {
            alert("文件:" + fileObj.name + "上传失败");
        },
        onUploadSuccess: function(file,data,response){
            data = JSON.parse(data);
            $("#imgBlock img").remove();
            $("#imgBlock").append("<img style='width:200px;' src='${base}/system/getImg?imgId=" + data.filePath + "'/>");
            $("#iconUrlImg").val(data.filePath);
        }
    });
</script>
</#macro>
